#!/usr/bin/python
# -*- coding: UTF-8 -*-

from time import sleep
from MiniBotControlLib import MiniBotControlLib
from BwSensorLib import BwSensorLib

# 声明控制库对象
mlib = MiniBotControlLib("udp")
# 声明传感器库对象
sensorlib = BwSensorLib(mlib)
# 连接机器人
ip = "10.10.100.254"
mlib.Connect(ip, 8899)

# 声音传感器测量大于200，点亮RGB亮红色，否则一直亮蓝色
def main():
   # RGB灯值
   # 红色：[255, 0, 0]，绿色：[0, 255, 0]，蓝色[0, 0, 255]， 熄灭：[0, 0, 0]
   rgbValue = [[255,0,0],[0,255,0],[0,0,255],[0,0,0]]
   while(True):
      voice = sensorlib.readVoiceSensor() # 读取声音传感器数据
      print("声音量：", voice)
      if(voice>200):
         sensorlib.setRGBLightSensor(rgbValue[0]) # 亮红灯
      else:
         sensorlib.setRGBLightSensor(rgbValue[2]) # 亮蓝灯
      sleep(0.2)

if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        print(" Program closed! ")
    pass


